<template>
  <div id="moreEdit">
      <div v-if="depttype==='单位'">
        <h1>基本信息情况</h1>
        <el-form :model="deptMoreeditForm" label-width="150px" :rules="deptMoreEditFormRules" ref="deptMoreeditForm" :inline="true" style="width:1000px">
          <el-form-item label="单位全称" prop="Name" style="width:570px;">
            <b>{{deptMoreeditForm.Name}}</b>
          </el-form-item>
          <el-form-item label="机构规格" prop="Jigouguige">
            <el-input v-model="deptMoreeditForm.Jigouguige" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="其他全称" prop="Qitaquancheng" style="width:570px;">
            <el-input v-model="deptMoreeditForm.Qitaquancheng" auto-complete="off" style="width:420px;"></el-input>
          </el-form-item>
          <el-form-item label="行业类别" prop="Hangyeleibie">
            <el-select v-model="deptMoreeditForm.Hangyeleibie" placeholder="请选择行业类别">
              <el-option v-for="(item,index) in hyoptions" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="京内京外" prop="Jingneijingwai" style="width:350px">
            <el-switch style="display: block;margin-top:9px" v-model="deptMoreeditForm.Jingneijingwai" active-color="#13ce66" inactive-color="#ff4949" active-text="京内" inactive-text="京外" active-value="京内" inactive-value="京外"></el-switch>
          </el-form-item>
          <el-form-item label="事业单位类型" prop="Shiyedanweileixing">
            <el-select v-model="deptMoreeditForm.Shiyedanweileixing" placeholder="请选择政治面貌">
              <el-option v-for="(item,index) in sydwoptions" :key="index" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="统一社会信用代码" prop="Xinyongdaima">
            <el-input v-model="deptMoreeditForm.Xinyongdaima" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="批准文号" prop="Pizhunwenhao">
            <el-input v-model="deptMoreeditForm.Pizhunwenhao" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="法人证书号" prop="Farenzhengshuhao">
            <el-input v-model="deptMoreeditForm.Farenzhengshuhao" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="单位设立时间" prop="Shelishijian">
            <el-date-picker v-model="deptMoreeditForm.Shelishijian" auto-complete="off"></el-date-picker>
          </el-form-item>
          <el-form-item label="组织机构代码" prop="Zuzhijigoudaima">
            <el-input v-model="deptMoreeditForm.Zuzhijigoudaima" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="法定代表人" prop="Fadingdaibiaoren">
            <el-input v-model="deptMoreeditForm.Fadingdaibiaoren" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="是否参照公务员法管理" prop="CanGong2" label-width="180px">
            <el-switch style="display: block;margin-top:9px" v-model="deptMoreeditForm.CanGong2" active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" active-value="是" inactive-value="否"></el-switch>
          </el-form-item>
        <h1>联系方式</h1>
          <el-form-item label="邮政编码" prop="Youbian">
            <el-input v-model="deptMoreeditForm.Youbian" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="固定电话" prop="Gudingdianhua">
            <el-input v-model="deptMoreeditForm.Gudingdianhua" auto-complete="off"></el-input>
          </el-form-item>
          <el-form-item label="通信地址" prop="Tongxindizhi" style="width:800px;">
            <el-input v-model="deptMoreeditForm.Tongxindizhi" auto-complete="off" style="width:570px;"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-button type="primary" @click.native="deptMoreeditFormSubmit" :loading="deptMoreeditFormLoading" style="margin-left:150px;">保存</el-button>
          <el-button @click.native="cancelEditForm">取消</el-button>
        </el-form>
      </div>
      <div v-else-if="depttype==='分类'">
        <h1>基本信息情况</h1>
        <el-form :model="bmflEditForm" label-width="150px" :rules="bmflEditFormRules" ref="bmflEditForm" :inline="true" style="width:1000px">
          <el-form-item label="分类名称" prop="Name" style="width:570px;">
            <el-input v-model="bmflEditForm.Name" auto-complete="off" style="width:420px;"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-button type="primary" @click.native="bmflEditFormSubmit" :loading="bmflEditFormLoading" style="margin-left:150px;">保存</el-button>
          <el-button @click.native="cancelEditForm">取消</el-button>
        </el-form>
      </div>
      <div v-else-if="depttype==='部门'">
        <h1>基本信息情况</h1>
        <el-form :model="bmflEditForm" label-width="150px" :rules="bmflEditFormRules" ref="bmflEditForm" :inline="true" style="width:1000px">
          <el-form-item label="部门名称" prop="Name" style="width:570px;">
            <el-input v-model="bmflEditForm.Name" auto-complete="off" style="width:420px;"></el-input>
          </el-form-item>
          <div style="clear:both"></div>
          <el-button type="primary" @click.native="bmflEditFormSubmit" :loading="bmflEditFormLoading" style="margin-left:150px;">保存</el-button>
          <el-button @click.native="cancelEditForm">取消</el-button>
        </el-form>
      </div>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',
  props: {
    unitInfoEdit: '',
    depttype: ''
  },
  watch: {
    unitInfoEdit (val) {
      this.deptMoreeditForm = val
      this.bmflEditForm = val
    }
    // $refs.tree2.getCurrentNode()
  },
  data () {
    return {
      deptMoreeditForm: {},
      deptMoreEditFormRules: {
        Hangyeleibie: [{ required: true, message: '请选择行业类别', trigger: 'blur' }],
        Jingneijingwai: [{ required: true, message: '请选择京内京外', trigger: 'blur' }],
        Shiyedanweileixing: [{ required: true, message: '请选择事业单位类型', trigger: 'blur' }],
        Xinyongdaima: [{ required: true, message: '请输入统一社会信用代码', trigger: 'blur' }]
      },
      deptMoreeditFormLoading: false,
      bmflEditForm: {},
      bmflEditFormRules: {
        Name: [{ required: true, message: '请输入名称', trigger: 'blur' }]
      },
      bmflEditFormLoading: false,
      deptEditswitch: false,
      moreDetailLoading: false,
      editLoading: false,
      deptMoreEditFormLoading: false,
      hyoptions: [{
        value: '科研事业单位',
        label: '科研事业单位'
      }, {
        value: '其他事业单位',
        label: '其他事业单位'
      }],
      sydwoptions: [{
        value: '公益一类',
        label: '公益一类'
      }, {
        value: '公益二类',
        label: '公益二类'
      }]
    }
  },
  methods: {
    noticeparent (ifrefresh) {
      this.$emit('cancelevent', ifrefresh)
    },
    cancelEditForm: function () {
      this.noticeparent(true)
    },
    bmflEditFormSubmit: function () {
      var _this = this
      this.$refs.bmflEditForm.validate((valid) => {
        if (valid) {
          _this.bmflEditFormLoading = true
          let para = {
            id: this.bmflEditForm.Id,
            name: this.bmflEditForm.Name
          }
          this.$http.post(`/unit/bumenfenleiedit`, para).then(function (response) {
            console.log(response.data.IsSuccess)
            if (response.data.IsSuccess === true) {
              _this.bmflEditFormLoading = false
              _this.$message({
                message: '保存成功',
                type: 'success'
              })
              _this.noticeparent(false)
            } else {
              console.log('保存失败:' + response.data.Msg)
              _this.$message({
                message: '保存失败:' + response.data.Msg,
                type: 'error'
              })
            }
            _this.bmflEditFormLoading = false
          }).catch(function (error) {
            console.log(error)
            _this.$message({
              message: '获取失败:' + error,
              type: 'error'
            })
          })
        }
      })
    },
    deptMoreeditFormSubmit () {
      var _this = this
      this.$refs.deptMoreeditForm.validate((valid) => {
        if (valid) {
          _this.deptMoreeditFormLoading = true
          let para = {
            id: this.deptMoreeditForm.Id,
            Name: this.deptMoreeditForm.Name,
            Jigouguige: this.deptMoreeditForm.Jigouguige,
            Qitaquancheng: this.deptMoreeditForm.Qitaquancheng,
            Hangyeleibie: this.deptMoreeditForm.Hangyeleibie,
            Jingneijingwai: this.deptMoreeditForm.Jingneijingwai,
            Shiyedanweileixing: this.deptMoreeditForm.Shiyedanweileixing,
            Xinyongdaima: this.deptMoreeditForm.Xinyongdaima,
            Pizhunwenhao: this.deptMoreeditForm.Pizhunwenhao,
            Farenzhengshuhao: this.deptMoreeditForm.Farenzhengshuhao,
            Shelishijian: this.deptMoreeditForm.Shelishijian,
            Zuzhijigoudaima: this.deptMoreeditForm.Zuzhijigoudaima,
            Fadingdaibiaoren: this.deptMoreeditForm.Fadingdaibiaoren,
            CanGong2: this.deptMoreeditForm.CanGong2,
            Youbian: this.deptMoreeditForm.Youbian,
            Gudingdianhua: this.deptMoreeditForm.Gudingdianhua,
            Tongxindizhi: this.deptMoreeditForm.Tongxindizhi
          }
          this.$http.post(`/unit/unitedit`, para).then(function (response) {
            console.log(response.data.IsSuccess)
            if (response.data.IsSuccess === true) {
              _this.deptMoreeditFormLoading = false
              _this.$message({
                message: '保存成功',
                type: 'success'
              })
              _this.noticeparent(false)
            } else {
              console.log('保存失败:' + response.data.Msg)
              _this.$message({
                message: '保存失败:' + response.data.Msg,
                type: 'error'
              })
            }
            _this.deptMoreeditFormLoading = false
          }).catch(function (error) {
            console.log(error)
            _this.$message({
              message: '获取失败:' + error,
              type: 'error'
            })
          })
        }
      })
    }
  },
  mounted () {
  }
}
</script>
